package cn.wolfcode.car.business.web.controller.business;



import cn.wolfcode.car.business.domain.Statement;
import cn.wolfcode.car.business.domain.StatementItem;
import cn.wolfcode.car.business.mapper.StatementItemMapper;
import cn.wolfcode.car.business.query.StatementItemQueryObject;
import cn.wolfcode.car.business.query.StatementQueryObject;
import cn.wolfcode.car.business.service.IStatementItemService;
import cn.wolfcode.car.business.service.IStatementService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 岗位控制器
 */
@Controller
    @RequestMapping("business/statementItem")
public class StatementItemController {
    //模板前缀
    private static final String prefix = "business/statementItem/";

    @Autowired
    private IStatementItemService statementItemService;
    @Autowired
    private IStatementService statementService;



    @RequestMapping("/itemDetail")
    public String itemDetail(Model model,Long statementId){
        Statement statement = statementService.get(statementId);
        if (Statement.STATUS_CONSUME.equals(statement.getStatus())) {
            model.addAttribute("statement", statement);
            return prefix + "edit";
        }
        model.addAttribute("statement", statement);
        return prefix + "detail";
    }

    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<StatementItem> query(StatementItemQueryObject qo){
        TablePageInfo<StatementItem> query = statementItemService.query(qo);
        return query;
    }

    @RequestMapping("saveItems")
    @ResponseBody
    public AjaxResult saveItems(@RequestBody List<StatementItem> statements) {
        System.out.println(statements);
        statementItemService.saveitems(statements);
        return AjaxResult.success();
    }

    @RequestMapping("pay")
    @ResponseBody
    public AjaxResult pay(Long statementId) {
        statementItemService.updatePay(statementId);
        return AjaxResult.success();
    }
}
